package com.ymatou.iapi.dglogin.testcase;

import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.common.lang.CipherUtil;
import com.ymatou.iapi.dglogin.parameter.SellerWxAuthLoginBean;
import com.ymatou.iapi.dglogin.parameter.UserWxInfo;
import com.ymatou.iapi.dglogin.parameter.WxLoginSession;
import com.ymatou.iapi.dglogin.service.SellerWxAuthLoginCall;
import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.database.model.DGThirdPartyBindInfo;
import com.ymttest.database.model.DGUserExtInfo;
import com.ymttest.database.model.DGUserInfo;
import com.ymttest.database.model.DGWxUnionidBindInfo;
import com.ymttest.database.sqlwapper.DGUserWapper;
import com.ymttest.utils.TestDataManager;
/**
*商家微信授权联登
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_SellerWxAuthLogin{
	private static SellerWxAuthLoginBean sellerwxauthloginBean;
	private static SellerWxAuthLoginCall sellerwxauthloginCall;
	DGUserWapper DGUserWapper;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("商家微信授权联登");
	}

	@Before
	public void caseUp() {
		sellerwxauthloginBean=new SellerWxAuthLoginBean();
		sellerwxauthloginCall=new SellerWxAuthLoginCall();
		DGUserWapper=new DGUserWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(sellerwxauthloginCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SellerWxAuthLogin_001() {
		Logger.start(true,"已注册商家微信授权联登(有unionid新openid),成功");
		try {
			UserCreateBean u= DGUserCallService.initUsercreateBean();
			u.setIscs(false);
			u.setMobile(TestDataManager.getPhoneNum());
			u.setMobileAreaCode("86");
			u.setUserType(1);
			u.setAppSource(DGUserCallService.DG_SellerWxApp);
			u.setWxAppName(DGUserCallService.TestWxsqSeller);
			//注册商家
			Integer sellerid=DGUserCallService.UserCreateCall(u);

			//新用户授权联登 等于注册
			sellerwxauthloginBean.setIv(TestDataManager.getUTF8Base64(DGUserCallService.IV));
//			wxauthloginBean.setIv(DGUserCallService.IV);
			WxLoginSession wxLoginSession=new WxLoginSession();
			wxLoginSession.setOpenId(u.getOpenId()+1);
			wxLoginSession.setSessionKey(TestDataManager.getUTF8Base64(DGUserCallService.SESSIONKEY));
			wxLoginSession.setUnionId(u.getUnionId());
			String loginSession = DGUserCallService.encryptWxLoginSession(wxLoginSession);
			sellerwxauthloginBean.setLoginSession(loginSession);
			//加密组装encryptedData
			UserWxInfo UserWxInfo=new UserWxInfo();
			UserWxInfo.setOpenId(u.getOpenId()+1);
			UserWxInfo.setUnionId(u.getUnionId());
			UserWxInfo.setAvatarUrl(u.getLogoUrl());
			UserWxInfo.setNickname(u.getNickname());
			UserWxInfo.setGender(1);
			String encryptedData=DGUserCallService.encryptWxEncryptedData(FormatUtil.beanToGSONString(UserWxInfo), DGUserCallService.IV, DGUserCallService.SESSIONKEY);
			sellerwxauthloginBean.setEncryptedData(encryptedData);
			sellerwxauthloginBean.setAppSource(u.getAppSource());
			sellerwxauthloginBean.setWxAppName(u.getWxAppName());
			sellerwxauthloginBean.setClientIp(u.getClientIp());
			sellerwxauthloginBean.setTerminalSource(u.getTerminalSource());
			sellerwxauthloginCall.setData(sellerwxauthloginBean);
			sellerwxauthloginCall.callService();			
			Logger.verifyEquals("true", sellerwxauthloginCall.getString("success"), "验证success");
			Logger.verifyNotNull(sellerwxauthloginCall.getString("userId"), "验证uid");
			Logger.verifyNotNull(sellerwxauthloginCall.getString("accessToken"), "验证accessToken");
			Logger.verifyNotNull(sellerwxauthloginCall.getString("cookieId"), "验证cookieId");
			Logger.verifyNotNull(sellerwxauthloginCall.getString("deviceId"), "验证deviceId");
//			Logger.verifyEquals(u.getUserGender().toString(),sellerwxauthloginCall.getString("userGender"), "验证userGender");
			List<DGThirdPartyBindInfo> tpinfo = DGUserWapper.selectDGThirdPartyBindInfo(sellerid);
			Logger.verifyEquals(2, tpinfo.size(), "创建2条绑定记录");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	

	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SellerWxAuthLogin_002() {
		Logger.start(true,"未注册商家微信授权联登,失败提示注册");
		try {
			UserCreateBean u= DGUserCallService.initUsercreateBean();
			u.setIscs(false);
			u.setMobile(TestDataManager.getPhoneNum());
			u.setMobileAreaCode("86");
			u.setUserType(1);
			u.setAppSource(DGUserCallService.DG_SellerWxApp);
			u.setWxAppName(DGUserCallService.TestWxsqSeller);
			//注册商家
//			Integer sellerid=DGUserCallService.UserCreateCall(u);

			//新用户授权联登 等于注册
			sellerwxauthloginBean.setIv(TestDataManager.getUTF8Base64(DGUserCallService.IV));
//			wxauthloginBean.setIv(DGUserCallService.IV);
			WxLoginSession wxLoginSession=new WxLoginSession();
			wxLoginSession.setOpenId(u.getOpenId()+1);
			wxLoginSession.setSessionKey(TestDataManager.getUTF8Base64(DGUserCallService.SESSIONKEY));
			wxLoginSession.setUnionId(u.getUnionId());
			String loginSession = DGUserCallService.encryptWxLoginSession(wxLoginSession);
			sellerwxauthloginBean.setLoginSession(loginSession);
			//加密组装encryptedData
			UserWxInfo UserWxInfo=new UserWxInfo();
			UserWxInfo.setOpenId(u.getOpenId()+1);
			UserWxInfo.setUnionId(u.getUnionId());
			UserWxInfo.setAvatarUrl(u.getLogoUrl());
			UserWxInfo.setNickname(u.getNickname());
			UserWxInfo.setGender(1);
			String encryptedData=DGUserCallService.encryptWxEncryptedData(FormatUtil.beanToGSONString(UserWxInfo), DGUserCallService.IV, DGUserCallService.SESSIONKEY);
			sellerwxauthloginBean.setEncryptedData(encryptedData);
			sellerwxauthloginBean.setAppSource(u.getAppSource());
			sellerwxauthloginBean.setWxAppName(u.getWxAppName());
			sellerwxauthloginBean.setClientIp(u.getClientIp());
			sellerwxauthloginBean.setTerminalSource(u.getTerminalSource());
			sellerwxauthloginCall.setData(sellerwxauthloginBean);
			sellerwxauthloginCall.callService();			
			Logger.verifyEquals("false", sellerwxauthloginCall.getString("success"), "验证success");
			//{"success":false,"errorCode":100,"errorMessage":"用户绑定信息不存在","userId":0,"nickname":"NickautoTest","logoUrl":"http://static.ymatou.com/content/images/weixin2d-new.png","userGender":1,"loginSession":"3D8FC0995D15F897CD628A4D93176993578EEC5FCE00B46A4728560E707D452F342611808096A65E290FBA960EBED119CF17F8454876FDA05EEA99E4823CFF4C059727F58CE7DD1CA0F35851B8320F72DD0032BA1954CAEEE3E35A3195F859A0"}
			Logger.verifyEquals(sellerwxauthloginBean.getLoginSession(),sellerwxauthloginCall.getString("loginSession"), "验证loginSession");
			Logger.verifyEquals(UserWxInfo.getGender().toString(), sellerwxauthloginCall.getString("userGender"), "验证userGender");
			Logger.verifyEquals(UserWxInfo.getAvatarUrl(), sellerwxauthloginCall.getString("logoUrl"), "验证logoUrl");
			Logger.verifyEquals(UserWxInfo.getNickname(), sellerwxauthloginCall.getString("nickname"), "验证nickname");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SellerWxAuthLogin_003() {
		Logger.start(true,"不输入loginSession失败");
		try {
			UserCreateBean u= DGUserCallService.initUsercreateBean();
			u.setIscs(false);
			u.setMobile(TestDataManager.getPhoneNum());
			u.setMobileAreaCode("86");
			u.setUserType(1);
			u.setAppSource(DGUserCallService.DG_SellerWxApp);
			u.setWxAppName(DGUserCallService.TestWxsqSeller);
			//注册商家
//			Integer sellerid=DGUserCallService.UserCreateCall(u);

			//新用户授权联登 等于注册
			sellerwxauthloginBean.setIv(TestDataManager.getUTF8Base64(DGUserCallService.IV));
//			wxauthloginBean.setIv(DGUserCallService.IV);
			WxLoginSession wxLoginSession=new WxLoginSession();
			wxLoginSession.setOpenId(u.getOpenId()+1);
			wxLoginSession.setSessionKey(TestDataManager.getUTF8Base64(DGUserCallService.SESSIONKEY));
			wxLoginSession.setUnionId(u.getUnionId());
			String loginSession = DGUserCallService.encryptWxLoginSession(wxLoginSession);
//			sellerwxauthloginBean.setLoginSession(loginSession);
			//加密组装encryptedData
			UserWxInfo UserWxInfo=new UserWxInfo();
			UserWxInfo.setOpenId(u.getOpenId()+1);
			UserWxInfo.setUnionId(u.getUnionId());
			UserWxInfo.setAvatarUrl(u.getLogoUrl());
			UserWxInfo.setNickname(u.getNickname());
			UserWxInfo.setGender(1);
			String encryptedData=DGUserCallService.encryptWxEncryptedData(FormatUtil.beanToGSONString(UserWxInfo), DGUserCallService.IV, DGUserCallService.SESSIONKEY);
			sellerwxauthloginBean.setEncryptedData(encryptedData);
			sellerwxauthloginBean.setAppSource(u.getAppSource());
			sellerwxauthloginBean.setWxAppName(u.getWxAppName());
			sellerwxauthloginBean.setClientIp(u.getClientIp());
			sellerwxauthloginBean.setTerminalSource(u.getTerminalSource());
			sellerwxauthloginCall.setData(sellerwxauthloginBean);
			sellerwxauthloginCall.callService();			
			Logger.verifyEquals("false", sellerwxauthloginCall.getString("success"), "验证success");
			Logger.verifyEquals("1", sellerwxauthloginCall.getString("errorCode"), "验证errorCode");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SellerWxAuthLogin_004() {
		Logger.start(true,"不输入iv失败");
		try {
			UserCreateBean u= DGUserCallService.initUsercreateBean();
			u.setIscs(false);
			u.setMobile(TestDataManager.getPhoneNum());
			u.setMobileAreaCode("86");
			u.setUserType(1);
			u.setAppSource(DGUserCallService.DG_SellerWxApp);
			u.setWxAppName(DGUserCallService.TestWxsqSeller);
			//注册商家
//			Integer sellerid=DGUserCallService.UserCreateCall(u);

			//新用户授权联登 等于注册
//			sellerwxauthloginBean.setIv(TestDataManager.getUTF8Base64(DGUserCallService.IV));
//			wxauthloginBean.setIv(DGUserCallService.IV);
			WxLoginSession wxLoginSession=new WxLoginSession();
			wxLoginSession.setOpenId(u.getOpenId()+1);
			wxLoginSession.setSessionKey(TestDataManager.getUTF8Base64(DGUserCallService.SESSIONKEY));
			wxLoginSession.setUnionId(u.getUnionId());
			String loginSession = DGUserCallService.encryptWxLoginSession(wxLoginSession);
			sellerwxauthloginBean.setLoginSession(loginSession);
			//加密组装encryptedData
			UserWxInfo UserWxInfo=new UserWxInfo();
			UserWxInfo.setOpenId(u.getOpenId()+1);
			UserWxInfo.setUnionId(u.getUnionId());
			UserWxInfo.setAvatarUrl(u.getLogoUrl());
			UserWxInfo.setNickname(u.getNickname());
			UserWxInfo.setGender(1);
			String encryptedData=DGUserCallService.encryptWxEncryptedData(FormatUtil.beanToGSONString(UserWxInfo), DGUserCallService.IV, DGUserCallService.SESSIONKEY);
			sellerwxauthloginBean.setEncryptedData(encryptedData);
			sellerwxauthloginBean.setAppSource(u.getAppSource());
			sellerwxauthloginBean.setWxAppName(u.getWxAppName());
			sellerwxauthloginBean.setClientIp(u.getClientIp());
			sellerwxauthloginBean.setTerminalSource(u.getTerminalSource());
			sellerwxauthloginCall.setData(sellerwxauthloginBean);
			sellerwxauthloginCall.callService();			
			Logger.verifyEquals("false", sellerwxauthloginCall.getString("success"), "验证success");
			Logger.verifyEquals("1", sellerwxauthloginCall.getString("errorCode"), "验证errorCode");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SellerWxAuthLogin_005() {
		Logger.start(true,"不输入encryptedData失败");
		try {
			UserCreateBean u= DGUserCallService.initUsercreateBean();
			u.setIscs(false);
			u.setMobile(TestDataManager.getPhoneNum());
			u.setMobileAreaCode("86");
			u.setUserType(1);
			u.setAppSource(DGUserCallService.DG_SellerWxApp);
			u.setWxAppName(DGUserCallService.TestWxsqSeller);
			//注册商家
//			Integer sellerid=DGUserCallService.UserCreateCall(u);

			//新用户授权联登 等于注册
			sellerwxauthloginBean.setIv(TestDataManager.getUTF8Base64(DGUserCallService.IV));
//			wxauthloginBean.setIv(DGUserCallService.IV);
			WxLoginSession wxLoginSession=new WxLoginSession();
			wxLoginSession.setOpenId(u.getOpenId()+1);
			wxLoginSession.setSessionKey(TestDataManager.getUTF8Base64(DGUserCallService.SESSIONKEY));
			wxLoginSession.setUnionId(u.getUnionId());
			String loginSession = DGUserCallService.encryptWxLoginSession(wxLoginSession);
			sellerwxauthloginBean.setLoginSession(loginSession);
			//加密组装encryptedData
			UserWxInfo UserWxInfo=new UserWxInfo();
			UserWxInfo.setOpenId(u.getOpenId()+1);
			UserWxInfo.setUnionId(u.getUnionId());
			UserWxInfo.setAvatarUrl(u.getLogoUrl());
			UserWxInfo.setNickname(u.getNickname());
			UserWxInfo.setGender(1);
			String encryptedData=DGUserCallService.encryptWxEncryptedData(FormatUtil.beanToGSONString(UserWxInfo), DGUserCallService.IV, DGUserCallService.SESSIONKEY);
//			sellerwxauthloginBean.setEncryptedData(encryptedData);
			sellerwxauthloginBean.setAppSource(u.getAppSource());
			sellerwxauthloginBean.setWxAppName(u.getWxAppName());
			sellerwxauthloginBean.setClientIp(u.getClientIp());
			sellerwxauthloginBean.setTerminalSource(u.getTerminalSource());
			sellerwxauthloginCall.setData(sellerwxauthloginBean);
			sellerwxauthloginCall.callService();			
			Logger.verifyEquals("false", sellerwxauthloginCall.getString("success"), "验证success");
			Logger.verifyEquals("1", sellerwxauthloginCall.getString("errorCode"), "验证errorCode");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SellerWxAuthLogin_006() {
		Logger.start(true,"不输入appSource失败");
		try {
			UserCreateBean u= DGUserCallService.initUsercreateBean();
			u.setIscs(false);
			u.setMobile(TestDataManager.getPhoneNum());
			u.setMobileAreaCode("86");
			u.setUserType(1);
			u.setAppSource(DGUserCallService.DG_SellerWxApp);
			u.setWxAppName(DGUserCallService.TestWxsqSeller);
			//注册商家
//			Integer sellerid=DGUserCallService.UserCreateCall(u);

			//新用户授权联登 等于注册
			sellerwxauthloginBean.setIv(TestDataManager.getUTF8Base64(DGUserCallService.IV));
//			wxauthloginBean.setIv(DGUserCallService.IV);
			WxLoginSession wxLoginSession=new WxLoginSession();
			wxLoginSession.setOpenId(u.getOpenId()+1);
			wxLoginSession.setSessionKey(TestDataManager.getUTF8Base64(DGUserCallService.SESSIONKEY));
			wxLoginSession.setUnionId(u.getUnionId());
			String loginSession = DGUserCallService.encryptWxLoginSession(wxLoginSession);
			sellerwxauthloginBean.setLoginSession(loginSession);
			//加密组装encryptedData
			UserWxInfo UserWxInfo=new UserWxInfo();
			UserWxInfo.setOpenId(u.getOpenId()+1);
			UserWxInfo.setUnionId(u.getUnionId());
			UserWxInfo.setAvatarUrl(u.getLogoUrl());
			UserWxInfo.setNickname(u.getNickname());
			UserWxInfo.setGender(1);
			String encryptedData=DGUserCallService.encryptWxEncryptedData(FormatUtil.beanToGSONString(UserWxInfo), DGUserCallService.IV, DGUserCallService.SESSIONKEY);
			sellerwxauthloginBean.setEncryptedData(encryptedData);
//			sellerwxauthloginBean.setAppSource(u.getAppSource());
			sellerwxauthloginBean.setWxAppName(u.getWxAppName());
			sellerwxauthloginBean.setClientIp(u.getClientIp());
			sellerwxauthloginBean.setTerminalSource(u.getTerminalSource());
			sellerwxauthloginCall.setData(sellerwxauthloginBean);
			sellerwxauthloginCall.callService();			
			Logger.verifyEquals("false", sellerwxauthloginCall.getString("success"), "验证success");
			Logger.verifyEquals("1", sellerwxauthloginCall.getString("errorCode"), "验证errorCode");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SellerWxAuthLogin_007() {
		Logger.start(true,"不输入wxAppName失败");
		try {
			UserCreateBean u= DGUserCallService.initUsercreateBean();
			u.setIscs(false);
			u.setMobile(TestDataManager.getPhoneNum());
			u.setMobileAreaCode("86");
			u.setUserType(1);
			u.setAppSource(DGUserCallService.DG_SellerWxApp);
			u.setWxAppName(DGUserCallService.TestWxsqSeller);
			//注册商家
//			Integer sellerid=DGUserCallService.UserCreateCall(u);

			//新用户授权联登 等于注册
			sellerwxauthloginBean.setIv(TestDataManager.getUTF8Base64(DGUserCallService.IV));
//			wxauthloginBean.setIv(DGUserCallService.IV);
			WxLoginSession wxLoginSession=new WxLoginSession();
			wxLoginSession.setOpenId(u.getOpenId()+1);
			wxLoginSession.setSessionKey(TestDataManager.getUTF8Base64(DGUserCallService.SESSIONKEY));
			wxLoginSession.setUnionId(u.getUnionId());
			String loginSession = DGUserCallService.encryptWxLoginSession(wxLoginSession);
			sellerwxauthloginBean.setLoginSession(loginSession);
			//加密组装encryptedData
			UserWxInfo UserWxInfo=new UserWxInfo();
			UserWxInfo.setOpenId(u.getOpenId()+1);
			UserWxInfo.setUnionId(u.getUnionId());
			UserWxInfo.setAvatarUrl(u.getLogoUrl());
			UserWxInfo.setNickname(u.getNickname());
			UserWxInfo.setGender(1);
			String encryptedData=DGUserCallService.encryptWxEncryptedData(FormatUtil.beanToGSONString(UserWxInfo), DGUserCallService.IV, DGUserCallService.SESSIONKEY);
			sellerwxauthloginBean.setEncryptedData(encryptedData);
			sellerwxauthloginBean.setAppSource(u.getAppSource());
//			sellerwxauthloginBean.setWxAppName(u.getWxAppName());
			sellerwxauthloginBean.setClientIp(u.getClientIp());
			sellerwxauthloginBean.setTerminalSource(u.getTerminalSource());
			sellerwxauthloginCall.setData(sellerwxauthloginBean);
			sellerwxauthloginCall.callService();			
			Logger.verifyEquals("false", sellerwxauthloginCall.getString("success"), "验证success");
			Logger.verifyEquals("1", sellerwxauthloginCall.getString("errorCode"), "验证errorCode");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SellerWxAuthLogin_008() {
		Logger.start(true,"encryptedData中没有openid数据登入失败");
		try {
			UserCreateBean u= DGUserCallService.initUsercreateBean();
			u.setIscs(false);
			u.setMobile(TestDataManager.getPhoneNum());
			u.setMobileAreaCode("86");
			u.setUserType(1);
			u.setAppSource(DGUserCallService.DG_SellerWxApp);
			u.setWxAppName(DGUserCallService.TestWxsqSeller);
			//注册商家
			Integer sellerid=DGUserCallService.UserCreateCall(u);

			//新用户授权联登 等于注册
			sellerwxauthloginBean.setIv(TestDataManager.getUTF8Base64(DGUserCallService.IV));
			WxLoginSession wxLoginSession=new WxLoginSession();
//			wxLoginSession.setOpenId(u.getOpenId()+1);
			wxLoginSession.setSessionKey(TestDataManager.getUTF8Base64(DGUserCallService.SESSIONKEY));
			wxLoginSession.setUnionId(u.getUnionId());
			String loginSession = DGUserCallService.encryptWxLoginSession(wxLoginSession);
			sellerwxauthloginBean.setLoginSession(loginSession);
			//加密组装encryptedData
			UserWxInfo UserWxInfo=new UserWxInfo();
//			UserWxInfo.setOpenId(u.getOpenId()+1);
			UserWxInfo.setUnionId(u.getUnionId());
			UserWxInfo.setAvatarUrl(u.getLogoUrl());
			UserWxInfo.setNickname(u.getNickname());
			UserWxInfo.setGender(1);
			String encryptedData=DGUserCallService.encryptWxEncryptedData(FormatUtil.beanToGSONString(UserWxInfo), DGUserCallService.IV, DGUserCallService.SESSIONKEY);
			sellerwxauthloginBean.setEncryptedData(encryptedData);
			sellerwxauthloginBean.setAppSource(u.getAppSource());
			sellerwxauthloginBean.setWxAppName(u.getWxAppName());
			sellerwxauthloginBean.setClientIp(u.getClientIp());
			sellerwxauthloginBean.setTerminalSource(u.getTerminalSource());
			sellerwxauthloginCall.setData(sellerwxauthloginBean);
			sellerwxauthloginCall.callService();			
			Logger.verifyEquals("false", sellerwxauthloginCall.getString("success"), "验证success");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SellerWxAuthLogin_009() {
		Logger.start(true,"商家微信授权联登,loginSession中unionid为空encryptedData的unionid数据库不存在,走注册新用户流程");
		try {
			UserCreateBean u= DGUserCallService.initUsercreateBean();
			u.setIscs(false);
			u.setMobile(TestDataManager.getPhoneNum());
			u.setMobileAreaCode("86");
			u.setUserType(1);
			u.setAppSource(DGUserCallService.DG_SellerWxApp);
			u.setWxAppName(DGUserCallService.TestWxsqSeller);
			//注册商家
//			Integer sellerid=DGUserCallService.UserCreateCall(u);

			//新用户授权联登 等于注册
			sellerwxauthloginBean.setIv(TestDataManager.getUTF8Base64(DGUserCallService.IV));
//			wxauthloginBean.setIv(DGUserCallService.IV);
			WxLoginSession wxLoginSession=new WxLoginSession();
			wxLoginSession.setOpenId(u.getOpenId()+1);
			wxLoginSession.setSessionKey(TestDataManager.getUTF8Base64(DGUserCallService.SESSIONKEY));
//			wxLoginSession.setUnionId(u.getUnionId());
			String loginSession = DGUserCallService.encryptWxLoginSession(wxLoginSession);
			sellerwxauthloginBean.setLoginSession(loginSession);
			//加密组装encryptedData
			UserWxInfo UserWxInfo=new UserWxInfo();
			UserWxInfo.setOpenId(u.getOpenId()+1);
			UserWxInfo.setUnionId(u.getUnionId());
			UserWxInfo.setAvatarUrl(u.getLogoUrl());
			UserWxInfo.setNickname(u.getNickname());
			UserWxInfo.setGender(1);
			String encryptedData=DGUserCallService.encryptWxEncryptedData(FormatUtil.beanToGSONString(UserWxInfo), DGUserCallService.IV, DGUserCallService.SESSIONKEY);
			sellerwxauthloginBean.setEncryptedData(encryptedData);
			sellerwxauthloginBean.setAppSource(u.getAppSource());
			sellerwxauthloginBean.setWxAppName(u.getWxAppName());
			sellerwxauthloginBean.setClientIp(u.getClientIp());
			sellerwxauthloginBean.setTerminalSource(u.getTerminalSource());
			sellerwxauthloginCall.setData(sellerwxauthloginBean);
			sellerwxauthloginCall.callService();			
			Logger.verifyEquals("false", sellerwxauthloginCall.getString("success"), "验证success");
			//{"success":false,"errorCode":100,"errorMessage":"用户绑定信息不存在","userId":0,"nickname":"NickautoTest","logoUrl":"http://static.ymatou.com/content/images/weixin2d-new.png","userGender":1,"loginSession":"3D8FC0995D15F897CD628A4D93176993578EEC5FCE00B46A4728560E707D452F342611808096A65E290FBA960EBED119CF17F8454876FDA05EEA99E4823CFF4C059727F58CE7DD1CA0F35851B8320F72DD0032BA1954CAEEE3E35A3195F859A0"}
			Logger.verifyEquals("false", sellerwxauthloginCall.getString("success"), "验证success");
			Logger.verifyEquals(UserWxInfo.getGender().toString(), sellerwxauthloginCall.getString("userGender"), "验证userGender");
			Logger.verifyEquals(UserWxInfo.getAvatarUrl(), sellerwxauthloginCall.getString("logoUrl"), "验证logoUrl");
			Logger.verifyEquals(UserWxInfo.getNickname(), sellerwxauthloginCall.getString("nickname"), "验证nickname");
			WxLoginSession rwxLoginSession = DGUserCallService.decryptWxLoginSession(sellerwxauthloginCall.getString("loginSession"));
			Logger.comment(FormatUtil.beanToGSONString(rwxLoginSession));
			//这里要用后面取到的UserWxInfo.unionid
			Logger.verifyEquals(UserWxInfo.getUnionId(), rwxLoginSession.getUnionId(), "验证UnionId");
			Logger.verifyEquals(wxLoginSession.getSessionKey(), rwxLoginSession.getSessionKey(), "验证getSessionKey");
			Logger.verifyEquals(wxLoginSession.getOpenId(), rwxLoginSession.getOpenId(), "验证getOpenId");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	@Ignore
	//这个接口不会openid匹配无此场景
	public void Tc_SellerWxAuthLogin_010() {
		Logger.start(true,"商家微信授权联登,openid匹配unionid在数据库不存在,成功");
		try {
			UserCreateBean u= DGUserCallService.initUsercreateBean();
			u.setIscs(false);
			u.setMobile(TestDataManager.getPhoneNum());
			u.setMobileAreaCode("86");
			u.setUserType(1);
			u.setAppSource(DGUserCallService.DG_SellerWxApp);
			u.setWxAppName(DGUserCallService.TestWxsqSeller);
			//注册商家
			Integer sellerid=DGUserCallService.UserCreateCall(u);

			//新用户授权联登 等于注册
			sellerwxauthloginBean.setIv(TestDataManager.getUTF8Base64(DGUserCallService.IV));
//			wxauthloginBean.setIv(DGUserCallService.IV);
			WxLoginSession wxLoginSession=new WxLoginSession();
			wxLoginSession.setOpenId(u.getOpenId());
			wxLoginSession.setSessionKey(TestDataManager.getUTF8Base64(DGUserCallService.SESSIONKEY));
//			wxLoginSession.setUnionId(u.getUnionId());
			String loginSession = DGUserCallService.encryptWxLoginSession(wxLoginSession);
			sellerwxauthloginBean.setLoginSession(loginSession);
			//加密组装encryptedData
			UserWxInfo UserWxInfo=new UserWxInfo();
			UserWxInfo.setOpenId(u.getOpenId());
//			UserWxInfo.setUnionId(u.getUnionId());
			UserWxInfo.setAvatarUrl(u.getLogoUrl());
			UserWxInfo.setNickname(u.getNickname());
			UserWxInfo.setGender(1);
			String encryptedData=DGUserCallService.encryptWxEncryptedData(FormatUtil.beanToGSONString(UserWxInfo), DGUserCallService.IV, DGUserCallService.SESSIONKEY);
			sellerwxauthloginBean.setEncryptedData(encryptedData);
			sellerwxauthloginBean.setAppSource(u.getAppSource());
			sellerwxauthloginBean.setWxAppName(u.getWxAppName());
			sellerwxauthloginBean.setClientIp(u.getClientIp());
			sellerwxauthloginBean.setTerminalSource(u.getTerminalSource());
			sellerwxauthloginCall.setData(sellerwxauthloginBean);
			sellerwxauthloginCall.callService();			
			Logger.verifyEquals("true", sellerwxauthloginCall.getString("success"), "验证success");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SellerWxAuthLogin_011() {
		Logger.start(true,"已注册普通用户调用商家微信授权联登,失败");
		try {
			UserCreateBean u= DGUserCallService.initUsercreateBean();
			Integer userid=DGUserCallService.UserCreateCall(u);

			//新用户授权联登 等于注册
			sellerwxauthloginBean.setIv(TestDataManager.getUTF8Base64(DGUserCallService.IV));
//			wxauthloginBean.setIv(DGUserCallService.IV);
			WxLoginSession wxLoginSession=new WxLoginSession();
			wxLoginSession.setOpenId(u.getOpenId()+1);
			wxLoginSession.setSessionKey(TestDataManager.getUTF8Base64(DGUserCallService.SESSIONKEY));
			wxLoginSession.setUnionId(u.getUnionId());
			String loginSession = DGUserCallService.encryptWxLoginSession(wxLoginSession);
			sellerwxauthloginBean.setLoginSession(loginSession);
			//加密组装encryptedData
			UserWxInfo UserWxInfo=new UserWxInfo();
			UserWxInfo.setOpenId(u.getOpenId()+1);
			UserWxInfo.setUnionId(u.getUnionId());
			UserWxInfo.setAvatarUrl(u.getLogoUrl());
			UserWxInfo.setNickname(u.getNickname());
			UserWxInfo.setGender(1);
			String encryptedData=DGUserCallService.encryptWxEncryptedData(FormatUtil.beanToGSONString(UserWxInfo), DGUserCallService.IV, DGUserCallService.SESSIONKEY);
			sellerwxauthloginBean.setEncryptedData(encryptedData);
			sellerwxauthloginBean.setAppSource(u.getAppSource());
			sellerwxauthloginBean.setWxAppName(u.getWxAppName());
			sellerwxauthloginBean.setClientIp(u.getClientIp());
			sellerwxauthloginBean.setTerminalSource(u.getTerminalSource());
			sellerwxauthloginCall.setData(sellerwxauthloginBean);
			sellerwxauthloginCall.callService();			
			Logger.verifyEquals("false", sellerwxauthloginCall.getString("success"), "验证success");
			Logger.verifyEquals("2", sellerwxauthloginCall.getString("errorCode"), "验证errorCode");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SellerWxAuthLogin_012() {
		Logger.start(true,"已删除商家微信授权联登(有unionid新openid),失败");
		try {
			UserCreateBean u= DGUserCallService.initUsercreateBean();
			u.setIscs(false);
			u.setMobile(TestDataManager.getPhoneNum());
			u.setMobileAreaCode("86");
			u.setUserType(1);
			u.setAppSource(DGUserCallService.DG_SellerWxApp);
			u.setWxAppName(DGUserCallService.TestWxsqSeller);
			//注册商家
			Integer sellerid=DGUserCallService.UserCreateCall(u);
			DGUserCallService.DeleteUser(sellerid);
			//新用户授权联登 等于注册
			sellerwxauthloginBean.setIv(TestDataManager.getUTF8Base64(DGUserCallService.IV));
//			wxauthloginBean.setIv(DGUserCallService.IV);
			WxLoginSession wxLoginSession=new WxLoginSession();
			wxLoginSession.setOpenId(u.getOpenId()+1);
			wxLoginSession.setSessionKey(TestDataManager.getUTF8Base64(DGUserCallService.SESSIONKEY));
			wxLoginSession.setUnionId(u.getUnionId());
			String loginSession = DGUserCallService.encryptWxLoginSession(wxLoginSession);
			sellerwxauthloginBean.setLoginSession(loginSession);
			//加密组装encryptedData
			UserWxInfo UserWxInfo=new UserWxInfo();
			UserWxInfo.setOpenId(u.getOpenId()+1);
			UserWxInfo.setUnionId(u.getUnionId());
			UserWxInfo.setAvatarUrl(u.getLogoUrl());
			UserWxInfo.setNickname(u.getNickname());
			UserWxInfo.setGender(1);
			String encryptedData=DGUserCallService.encryptWxEncryptedData(FormatUtil.beanToGSONString(UserWxInfo), DGUserCallService.IV, DGUserCallService.SESSIONKEY);
			sellerwxauthloginBean.setEncryptedData(encryptedData);
			sellerwxauthloginBean.setAppSource(u.getAppSource());
			sellerwxauthloginBean.setWxAppName(u.getWxAppName());
			sellerwxauthloginBean.setClientIp(u.getClientIp());
			sellerwxauthloginBean.setTerminalSource(u.getTerminalSource());
			sellerwxauthloginCall.setData(sellerwxauthloginBean);
			sellerwxauthloginCall.callService();			
			Logger.verifyEquals("false", sellerwxauthloginCall.getString("success"), "验证success");
//			Logger.verifyNotNull(sellerwxauthloginCall.getString("userId"), "验证uid");
//			Logger.verifyNotNull(sellerwxauthloginCall.getString("accessToken"), "验证accessToken");
//			Logger.verifyNotNull(sellerwxauthloginCall.getString("cookieId"), "验证cookieId");
//			Logger.verifyNotNull(sellerwxauthloginCall.getString("deviceId"), "验证deviceId");
////			Logger.verifyEquals(u.getUserGender().toString(),sellerwxauthloginCall.getString("userGender"), "验证userGender");
//			List<DGThirdPartyBindInfo> tpinfo = DGUserWapper.selectDGThirdPartyBindInfo(sellerid);
//			Logger.verifyEquals(2, tpinfo.size(), "创建2条绑定记录");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}